package kr.hkit.powerjava.chapter08.Programming;

/**
 * 은행 계좌 
 * owner 소유주 
 * AccountNumber 계좌번호
 * balance - 잔액
 * 
 * @author hkit
 * 
 */
public class BankAccount {

	private String owner;
	private int accountNumber;
	private int balance;

	public int getBalance() {
		return balance;
	}

	public void setBalance(int balance) {
		this.balance = balance;
	}

	public BankAccount(String owner, int accountNumber, int balance) {
		super();
		this.owner = owner;
		this.accountNumber = accountNumber;
		this.balance = balance;
	}

	public void deposit(int amount) {
		balance += amount;
	}

	public int withdraw(int amount) {
		if (balance < amount || balance == 0) {
			System.out.println("출급 불가 잔액: "+balance);
			return -1;
		}else{
			balance -= amount;
			return amount;
		}
	}
	
	public int transfer(int amount, BankAccount otherAccount){
		
		if (balance < amount || balance == 0) {
			System.out.println("송금 불가 잔액: "+balance);
			return -1;
		}else{
			balance -= amount;
			otherAccount.setBalance(otherAccount.getBalance()+amount);
			return amount;
		}
	}

	@Override
	public String toString() {
		return "BankAccount [owner=" + owner + ", accountNumber="
				+ accountNumber + ", balance=" + balance + "]";
	}
}
